import becker.robots.*;
public class main {
	static MazeCity ICS = new MazeCity(10,10);
	static superRobot abubakr = new superRobot(ICS,0,0,Direction.EAST);
	static int possible = 0;
	static boolean[][] open =new  boolean[10][10];
	static int previousX = 99;
	static int previousY = 99;
	static int x = 0, y = 0;
	public static void main (String args[]){
		
		//Set all intersections to possible moves. 
		for (int i = 0; i < 9; i++){
			for (int x = 0; x < 9; x++){
				open[i][x] = true;
			}
		}
		while (!abubakr.frontIsClear()){
			abubakr.turnLeft();
		}
		abubakr.move();
		//While the end of the maze is not reached.
		while (abubakr.getAvenue() != 9 || abubakr.getStreet() != 9) {				
			possible = abubakr.returnPossible(open);
			System.out.println(possible);
			previousX = abubakr.getPreviousX();
			previousY = abubakr.getPreviousY();
			System.out.println("Previous:" + previousX + "," + previousY);
			//If there is only one possible path, take it.
			if (possible == 1){
				open[abubakr.getAvenue()][abubakr.getStreet()] = false; //If only one path, that means it is a dead end. So close the path.
				System.out.println(open[abubakr.getAvenue()][abubakr.getStreet()]);				
				abubakr.changeDir(Direction.EAST);
				if (abubakr.frontIsClear() && open[abubakr.getAvenue()+1][abubakr.getStreet()]){
					abubakr.move();
				}
				abubakr.changeDir(Direction.NORTH);
				if (abubakr.frontIsClear() && open[abubakr.getAvenue()][abubakr.getStreet()-1]){
					abubakr.move();
				}
				abubakr.changeDir(Direction.WEST);
				if (abubakr.frontIsClear() && open[abubakr.getAvenue()-1][abubakr.getStreet()]){
					abubakr.move();
				}
				abubakr.changeDir(Direction.SOUTH);
				if (abubakr.frontIsClear() && open[abubakr.getAvenue()][abubakr.getStreet()+1]){
					abubakr.move();
				}
			} else {				
				x = abubakr.setX(x);
				y = abubakr.setY(y);
				System.out.println("X:" + x + " Y:" + y);
				while (!(abubakr.frontIsClear() && open[x][y] && x != previousX && y != previousY)){
					abubakr.turnLeft();				
					x = abubakr.setX(x);
					y = abubakr.setY(y);
					System.out.println("X:" + x + " Y:" + y);
				}
				abubakr.move();
			}

		}
	}
}